package br.com.mubi.admin;

import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.SessionScoped;
import javax.faces.context.FacesContext;

import br.com.mubi.review.FilmeBean;

@ManagedBean
@SessionScoped
public class AdministracaoBean {

	@ManagedProperty(value = "#{filmeBean}")
	private FilmeBean filmeBean;
	private AdministracaoRN administracaoRN;
	
	public AdministracaoBean() {
		this.administracaoRN = new AdministracaoRN();
	}
	
	public String carregarPaginaAdm() {
		this.administracaoRN.listarTodosFilme();
		this.administracaoRN.listarTodosUsuarios();
		return "/admin/administracao.jsf";
	}
	
	public String exibirFilmeSelecionado() {
		this.filmeBean.getFilmeRN().setFilme(this.administracaoRN.getFilme());
		return this.filmeBean.getFilmeRN().exibirFIlmeSelecionado();
	}
	
	public void excluirReview(){
		this.administracaoRN.excluirReview(FacesContext.getCurrentInstance());
	}
	
	public void excluirUsuario(){
		this.administracaoRN.excluirUsuario(FacesContext.getCurrentInstance());
	}
	
	public void alterarUsuario() {
		this.administracaoRN.salvarUsuario(FacesContext.getCurrentInstance());
		this.administracaoRN.listarTodosUsuarios();
	}

	public AdministracaoRN getAdministracaoRN() {
		return administracaoRN;
	}

	public void setAdministracaoRN(AdministracaoRN administracaoRN) {
		this.administracaoRN = administracaoRN;
	}

	public FilmeBean getFilmeBean() {
		return filmeBean;
	}

	public void setFilmeBean(FilmeBean filmeBean) {
		this.filmeBean = filmeBean;
	}
}
